package com.xyazm.order.mq.consumer;

import com.alibaba.fastjson.JSONObject;
import com.xyazm.common.constants.RocketMqConstant;
import com.xyazm.order.domain.mq.ActualRefundDTO;
import com.xyazm.order.service.IAfterSaleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 监听 真正退款 消息 2.0
 * @Author: xuyou
 * @Date: 2022/7/1 16:22
 */
@Slf4j
@Component
@RocketMQMessageListener(
        topic = RocketMqConstant.ACTUAL_REFUND_TOPIC,
        consumerGroup = RocketMqConstant.ACTUAL_REFUND_CONSUMER_GROUP,
        consumeMode = ConsumeMode.CONCURRENTLY,
        messageModel = MessageModel.CLUSTERING,
        consumeThreadMax = 1
)
public class ActualRefundListener extends AbstractRocketMqListener {

    @Autowired
    private IAfterSaleService orderAfterSaleService;

    @Override
    public void onMessage(String message) {
        log.info("ActualRefundListener message:{}", message);
        ActualRefundDTO actualRefundDTO = JSONObject.parseObject(message, ActualRefundDTO.class);
        // 执行实际退款
        orderAfterSaleService.refundMoney(actualRefundDTO);
    }

}
